{extend name="public:base"}
{block name="main"}
<form class="layui-form">
  <div class="demoTable">
    条件搜索：
    <div class="layui-inline">
      <select name="cateid">
        <option value="">请选择分类</option>
        {foreach $catelist as $v}
        <option value="{$v['cateid']}">{$v['catename']}</option>
        {/foreach}
      </select> 
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入关键字">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="start" id="start"  placeholder="请输入开始时间">
    </div>
    <div class="layui-inline">
      <input class="layui-input" name="end" id="end"  placeholder="请输入结束时间">
    </div>

    <button class="layui-btn" data-type="reload" lay-filter="submit" lay-submit>搜索</button>
    <button class="layui-btn layui-btn-primary" type="reset" data-type="reload" lay-filter="reset" lay-submit>重置</button>

  </div>
</form>
<table class="layui-table" lay-data="{height:650,url:'{:Url('newslist')}',where:{cateid:'{:input('cateid')}'}, page:true, id:'newslist'}" lay-filter="table">
  <thead>
    <tr>
      <th lay-data="{field:'newsid', width:50, sort: true}">ID</th>
      <th lay-data="{field:'catename', width:100}">分类</th>
      <th lay-data="{field:'thumb', width:80}">缩略图</th>
      <th lay-data="{field:'title', width:180}">标题</th>
      <th lay-data="{field:'keyword', width:180}">关键字</th>
      <th lay-data="{field:'hits', width:80,sort: true}">点击量</th>
      <th lay-data="{field:'status', width:80}">状态</th>
      <th lay-data="{field:'addtime', width:180, sort: true}">添加时间</th>
     
      <th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>

<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;
   laydate.render({
      elem: '#start',
      max: 0
   });
    laydate.render({
      elem: '#end',
      max: 1
   });
   
  var $ = layui.$;

  //搜索
  form.on('submit(submit)', function(data){

    var keyword=$("input[name='keyword']").val();
    var start=$("input[name='start']").val();
    var end=$("input[name='end']").val();
    var cateid=$("select[name='cateid']").val();

    table.reload('newslist', {
    where: { 
      keyword:keyword,
      start:start,
      end:end,
      cateid:cateid
    }
  });

    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });

  //重置
  form.on('submit(reset)', function(data){

    $("input").val("");
    table.reload('newslist', {
      where: { 
        keyword:"",
        start:"",
        end:"",
        cateid:""
      }
    });
    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
  });


  table.on('tool(table)', function(obj){
    var data = obj.data;

    if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('newsdel')}",{'newsid': data.newsid},function(data){
           if(data=='1'){
              alert();
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="/admin.php/news/newsinfo/newsid/"+data.newsid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    }
  });

    //图片查看
  layer.photos({
    photos: 'div'
    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });


});

</script>
{/block}